home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre2.z / postgre2 / ref / postquel / defineindex < prev    next >
Encoding:
Text File  |  1992-08-27  |  3.1 KB  |  146 lines

  1. .\" XXX standard disclaimer belongs here....
  2. .\" $Header: /private/postgres/ref/postquel/RCS/defineindex,v 1.8 1992/07/14 05:54:17 ptong Exp $
  3. .SP "DEFINE INDEX" COMMANDS 6/14/90
  4. .XA 2 "Define Index"
  5. .uh NAME
  6. .lp
  7. define index \*- construct a secondary index
  8. .uh SYNOPSIS
  9. .lp
  10. .(l
  11. \fBdefine\fR [\fBarchive\fR] \fBindex\fR index-name
  12.     \fBon\fR classname \fBusing\fR am-name
  13.     \fB(\fR attname\-1 type_class\-1 { , attname\-i type_class\-i } \fB)\fR
  14. .)l
  15. .uh DESCRIPTION
  16. .lp
  17. This command constructs an index
  18. called
  19. .i index-name.
  20. If the
  21. .b archive
  22. keyword is absent,
  23. the
  24. .i classname
  25. class is indexed.
  26. When
  27. .b archive
  28. is present,
  29. an index is created
  30. on the archive class associated with the
  31. .i classname
  32. class.
  33. .lp
  34. .i Am-name
  35. is the name of the access method which is used for the index.
  36. .lp
  37. The key fields for the index are specified as a collection of
  38. attribute names and associated
  39. .i "operator classes" .
  40. An operator class is used to specify the operators
  41. to be used for a particular index.
  42. For example,
  43. a btree index on four-byte integers would use the
  44. .i int4_ops
  45. class;
  46. this operator class includes comparison functions for
  47. four-byte integers.
  48. .lp
  49. \*(PP Version \*(PV provides btree and rtree access methods
  50. for secondary indices.
  51. The operator classes defined on btrees are
  52. .(l
  53. .ft C
  54. int2_ops    char_ops
  55. int4_ops    char16_ops
  56. int24_ops    oid_ops
  57. int42_ops    text_ops
  58. floag4_ops    abstime_ops
  59. float8_ops
  60. .ft
  61. .)l
  62. The
  63. .i int24_ops
  64. operator class is useful for constructing indices on int2 data,
  65. and doing comparisons against int4 data in query qualifications.
  66. Similarly,
  67. .i int42_ops
  68. support indices on int4 data that is to be compared against int2
  69. data in queries.
  70. .lp
  71. The \*(PP query optimizer will consider using b-tree indices
  72. in a scan whenever an indexed attribute is involved in a comparison
  73. using one of
  74. .(b
  75. .ft C
  76. <    <=    =    >=    >
  77. .ft
  78. .)b
  79. .lp
  80. The operator classes defined on rtrees are
  81. .(l
  82. .ft C
  83. box_ops    poly_ops
  84. bigbox_ops
  85. .ft
  86. .)l
  87. Both of these support indices on the
  88. .q box
  89. datatype in \*(PP.
  90. The difference between them is that
  91. .i bigbox_ops
  92. scales box coordinates down,
  93. to avoid floating point exceptions from doing
  94. multiplication,
  95. addition,
  96. and subtraction on very large floating-point coordinates.
  97. If the field on which your rectangles lie is about 20,000
  98. units square or larger,
  99. you should use
  100. .i bigbox_ops .
  101. The
  102. .i poly_ops
  103. operator class supports rtree indices on
  104. .q polygon
  105. data.
  106. .lp
  107. The \*(PP query optimizer will consider using an r-tree index
  108. whenever an indexed attribute is involved in a comparison using
  109. one of
  110. .(b
  111. .ft C
  112. <<    &<    &>    >>    @    ~=    &&
  113. .ft
  114. .)b
  115. .uh EXAMPLES
  116. .lp
  117. Create a btree index on the emp class using the age attribute.
  118. .(b
  119. .ft C
  120. define index empindex on emp using btree (age int4_ops)
  121. .ft
  122. .)b
  123. .lp
  124. Create a btree index on employee name.
  125. .(b
  126. .ft C
  127. define index empname
  128.     on emp using btree (name char16_ops)
  129. .ft
  130. .)b
  131. .lp
  132. Create an rtree index on the bounding rectangle of cities.
  133. .(b
  134. .ft C
  135. define index cityrect
  136.     on city using rtree (boundbox box_ops)
  137. .ft
  138. .)b
  139. .uh BUGS
  140. .lp
  141. Archive indices are not supported in Version \*(PV.
  142. .lp
  143. There should be an access method designers guide.
  144. .lp
  145. Indices may only be defined on a single key.
  146.